//
//  PickerQueryViewModel.swift
//  cxd4iphone
//
//  Created by hexy on 12/26/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit
import ReactiveCocoa

class PickerQueryViewModel: NSObject {
    
    static let shared = PickerQueryViewModel()
    
    private override init() {
        
        pickerQueryModel = PickerQueryModel(dict: ["":""])
    }
    
    private var pickerQueryModel: PickerQueryModel

    var loansDateQuery: [PickerModel] {
        
        return pickerQueryModel.loansDateQuery ?? [PickerModel(dict:["":""])]
    }

    
    var loansRateQuery: [PickerModel] {
        
        return pickerQueryModel.loansRateQuery ?? [PickerModel(dict:["":""])]
    }
    
    
    var billStatusQuery: [PickerModel] {
        
        return pickerQueryModel.billStatusQuery ?? [PickerModel(dict:["":""])]
    }
    
    var billDateQuery: [PickerModel] {
        
        return pickerQueryModel.billDateQuery ?? [PickerModel(dict:["":""])]
    }

    
    
    var loanInvestStatus: [PickerModel] {
        
        return pickerQueryModel.loanInvestStatus ?? [PickerModel(dict:["":""])]
    }
    
    func loadPickerQueryData() -> RACSignal {
        
        return RACSignal.createSignal({ (subscriber) -> RACDisposable! in
            
            APIManager.loadQueryData().subscribeNext({ (result) -> Void in
                
//                                                xx_JsonPrint(dict: result)
                
                let dict = result as! [String: AnyObject]
                
                self.pickerQueryModel = PickerQueryModel(dict: dict)
                
                subscriber.sendCompleted()
                
                }, error: { (error) -> Void in
                    
                    subscriber.sendError(error)
            })
            
            return RACDisposable(block: {})
        })
    }
    
}
